Skip to content

perf: defer per-cell AI completion work - #12243

Merged
kirangadhave merged 6 commits into
mainfrom
kg/cell-ai
Dec 3, 2026
Merged

kirangadhave merged 6 commits into
mainfrom
kg/cell-ai

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Opening the inline AI prompt used to re-render every cell editor and each cell mounted a chat client. This change subscribes each editor to its own target state and creates a chat client on submit. It addresses the cell-completion portion of MO-8795.

Open the prompt in A   → promote A’s editor and mount its prompt
Submit in A           → start A’s stream
Switch to B           → show B’s prompt while A’s stream continues
Return to A           → review the proposal in the same editor

The staged comparison keeps its historical pane read-only. Reject returns focus to the prompt. Accept supports an empty replacement and preserves the selection when the proposed code is identical.

completion.mp4

Inline completion ready to accept

Staged comparison with read-only history

Opening the AI prompt in one cell caused every cell editor to commit,
and idle cells each retained a chat client. Subscribe by cell and
create the client only when a prompt is submitted.

Keep requests independent of the visible prompt so switching cells
preserves in-flight proposals. Keep the original editor mounted during
comparisons to preserve its selection and restore focus.
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 1142a8d.

@kirangadhave
kirangadhave requested a balanced review from Copilot December 2, 2026 18:53
@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label Dec 2, 2026
@kirangadhave
kirangadhave marked this pull request as ready for review December 2, 2026 18:53
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.35% 28713 / 41402
🔵 Statements 69.3% 29271 / 42235
🔵 Functions 64.75% 6909 / 10669
🔵 Branches 64.82% 16842 / 25979
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/components/editor/ai/ai-completion-editor.tsx 94.35% 86.51% 93.93% 94.11% 123, 156-161, 169, 214, 486
frontend/src/components/editor/ai/completion-utils.ts 67.39% 45% 63.63% 67.39% 136, 146, 214-250
frontend/src/components/editor/cell/code/cell-editor.tsx 61.06% 43.9% 54.83% 61.53% 143-153, 157-167, 172-174, 180-189, 194-197, 218-244, 332-348, 372, 379, 396, 399-400, 429-447, 492, 495, 510
frontend/src/core/ai/state.ts 94.28% 100% 77.77% 96.96% 150-153
Generated in workflow #26500 for commit 1142a8d by the Vitest Coverage Report Action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Delayed autofocus can still refocus the prompt and select an existing draft after the user tabs away, allowing the next keystroke to overwrite it.

2 open issues
What changed in this PR

Defers inline AI completion work in marimo’s notebook editor, reducing work in unrelated cells while preserving proposals across target switches.

Changes:

  • Subscribes editors to cell-specific AI targets and creates chat clients on submission.
  • Preserves editor instances and improves comparison, acceptance, and focus handling.
  • Adds render-isolation, streaming, cancellation, and cursor tests.
File Description
frontend/​src/​core/​ai/​state.ts Adds cell-specific target subscriptions.
frontend/​src/​components/​editor/​cell/​code/​cell-editor.tsx Integrates targeted subscriptions and content replacement.
frontend/​src/​components/​editor/​ai/​completion-utils.ts Accepts precomputed notebook context.
frontend/​src/​components/​editor/​ai/​ai-completion-editor.tsx Defers chat creation and updates completion interactions.
frontend/​src/​components/​editor/​ai/​__tests__/​completion-utils.test.ts Updates context-building tests.
frontend/​src/​components/​editor/​__tests__/​cell-renders.test.tsx Tests render isolation and completion lifecycle behavior.

Review effort: Balanced

mscolnick
mscolnick previously approved these changes Dec 2, 2026
@kirangadhave
kirangadhave merged commit 1b149d0 into main Dec 3, 2026
31 checks passed
@kirangadhave
kirangadhave deleted the kg/cell-ai branch December 3, 2026 04:43
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.26.1-dev112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants